#include "LoadBalance.h"
#include <atomic>

class RoundRobinStrategy : public LoadBalanceStrategy
{
public:
    RoundRobinStrategy()
    {
        m_index = 0;
    }

    ServiceItem Select(const std::string& name, const std::vector<ServiceItem>& services) override
    {
        if (m_index >= services.size())
        {
            m_index = 0;
        }
        // Using fetch_add for thread-safe increment
        size_t index = m_index.fetch_add(1) % services.size();

        return services[index];
    }
private:
    std::atomic<int> m_index;
};